package com.example.datasource.config;


/**
 * @Description : 用于存储动态数据源的key
 * @Author : Bruce Lee
 * @CreateTime : 2024/4/16
 */

public class DynamicDatasourceHolder {


    /**
     * 至于如何通过key拿到数据源对象，SpringBoot内部已经封装好了
     */

    private static final ThreadLocal<String> DATASOURCE_HOLDER = new ThreadLocal<>();

    public static String getDataSource() {
        return DATASOURCE_HOLDER.get();
    }
    public static void setDataSource(String dataSourceKey) {
        DATASOURCE_HOLDER.set(dataSourceKey);
    }
    public static void removeDataSource() {
        DATASOURCE_HOLDER.remove();
    }

}
